home *** CD-ROM | disk | FTP | other *** search
- Path: prairienet.org!sjmccaug
- From: sjmccaug@prairienet.org (Scott J. McCaughrin)
- Newsgroups: comp.lang.c++
- Subject: Re: [Q]Assigning function pointer in C/C++.
- Date: 20 Jan 1996 04:10:19 GMT
- Organization: University of Illinois at Urbana
- Message-ID: <4dppvb$6b3@vixen.cso.uiuc.edu>
- References: <4doc42$gsb@bmdhh222.bnr.ca> <DL3JJu.5nB.0.queen@torfree.net>
- Reply-To: sjmccaug@prairienet.org (Scott J. McCaughrin)
- NNTP-Posting-Host: firefly.prairienet.org
-
-
- In a previous article, ray.fallon@nt.com (Ray Fallon) says:
-
- >bh332@freenet.toronto.on.ca (Karim Ladha) wrote:
- >>
- >>
- >>How is it possible to assign a declared variable in C++ a pointer to
- >>some function member? If you know of a solution, post. Greatly appreciated.
- >>
- >>In C for example;
- >>
- >>...
- >>void( far *MyFunc )();
- >>...
- >>...
- >>
- >>Thank you,
- >> Karim A.Ladha - BH332@TorFree.Net
- >>
- >>PS: Using BC++ v4.0 for Windows(tm) - DOS Application.
- >>
- >>--
- >>
- >
- >Hi there Karim,
- >
- >I response to your question, assigment of pointers to member functions is
- >not possible for the following reason :
- >
- >In 'C' you can only have one instance of a function at any one time. In
- >C++ you can have multiple instances of a class (i.e. objects) and the
- >pointer to the function would not be able to know which object you are
- >referring to. In any case, it is possible to use other methods, and
- >theoritically they are more sound methods. Use the principle of
- >polymorphism. There is no scenario where you think that pointers to
- >functions can be used and polymorphism cannot. Consider the following
- >scenario :
- As usual, the C++ crowd has to bury us with voluminous programming examples
- which only serve to obfuscate the issue at hand. Why is simplicity so
- abhorrent to C++'ers? The author didn't ask about 'member' functions, so
- even a 'friend' function would have sufficed. The simple answer is that
- functions -- like arrays -- represent their addresses when appearing as
- names by themselves. Thus if 'SomeFunc' were a function of 0-arity returning
- void, just say: MyFunc = SomeFunc;
-
- -- Scott McC.
-